package acwing.bfs;

import java.awt.*;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

/**
 * 全球变暖
 *
 * @author yang
 * @date 2021/12/8
 */
public class 全球变暖 {

    static int N = 1010;
    static int n;
    static char[][] g = new char[N][N];
    static boolean[][] st = new boolean[N][N];
    static int[] dx = new int[] {-1,0,1,0};
    static int[] dy = new int[] {0,1,0,-1};

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            char[] chars = sc.next().toCharArray();
            for (int j = 0; j < n; j++) {
                g[i][j] = chars[j];
            }
        }
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (!st[i][j] && g[i][j] == '#') {
                    if (bfs(i,j)) cnt++;
                }
            }
        }
        System.out.println(cnt);
    }

    private static boolean bfs(int x, int y) {

        Queue<PII> q = new LinkedList<>();
        q.add(new PII(x,y));
        st[x][y] = true;
        int total = 0;//当前位置连通陆地的数量
        int bound = 0;//被淹没陆地的数量
        while (!q.isEmpty()) {
            total++;
            boolean is_bound = false;//判断岛屿是否被淹没
            PII t = q.poll();
            for (int i = 0; i < 4; i++) {
                int a = t.x + dx[i];
                int b = t.y + dy[i];
                if (a < 0 || a >= n || b < 0 || b >= n) continue;
                if (st[a][b]) continue;
                if (g[a][b] == '.') {
                    is_bound = true;
                    continue;
                }
                q.add(new PII(a, b));
                st[a][b] = true;
            }
            if (is_bound) bound++;
        }
        return bound == total;
    }
}
class PII {
    public int x;
    public int y;

    public PII(int x, int y) {
        this.x = x;
        this.y = y;
    }
}
